<template>
	<view class="cart">
		<view class="cart-container" v-if="cart.length !== 0">
				<my-address></my-address>
				<view class="cart-title">
					<image class="cart-icon" src="/static/cart2.png" mode=""></image>
					<text class="cart-title-text">购物车</text>
				</view>
				
				<uni-swipe-action>
					<block v-for="(goods, i) in cart" :key="i">
						<uni-swipe-action-item :options="options" @click="swipeClickHandler(goods)">
							<my-goods :goods="goods" @num-change="numberChangeHandel" :show-box="true" :showRadio="true" @radio-click="radioChangeHandel"></my-goods>
						</uni-swipe-action-item>
						
					</block>
				</uni-swipe-action>
				
				<my-settle></my-settle>
				
		</view>
		
		<!-- 购物车没有数据时显示 -->
		<view class="empty-cart" v-else>
			<image class="empty-cart-img" src="/static/empty-cart.png"></image>
			<text class="empty-cart-text">空空如也~</text>
		</view>
	</view>
</template>

<script>
	import badge from '@/mixins/tabbarBadge.js'
	import {mapState, mapMutations} from 'vuex'
	export default {
		mixins: [badge],

		data() {
			return {
				options: [
					{
						text: '删除',
						style: {
							backgroundColor: '#C00000'
						}
					}
				]
			};
		},
		computed: {
			...mapState('my-cart', ['cart'])
		},
		methods: {
			...mapMutations('my-cart', ['updateState', 'updateGoodsCount', 'removeGoods']),
			radioChangeHandel(e) {
				this.updateState(e);
			},
			numberChangeHandel(e) {
				this.updateGoodsCount(e)
			},
			swipeClickHandler(goods) {
				this.removeGoods(goods.goods_id);
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: white;
	}
	.cart-icon {
		width: 20px;
		height: 20px;
	}
	.cart-title {
		padding: 5px;
		display: flex;
		align-items: center;
		.cart-title-text {
			margin-left: 5px;
		}
	}
	.cart-container {
		padding-bottom: 50px;
	}
	.empty-cart {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		height: 100vh;
		.empty-cart-img {
			width: 100px;
			height: 100px;
		}
		.empty-cart-text {
			color: gray;
			margin-top: 15px;
			font-size: 14px;
		}
	}
</style>
